<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class MapPointRule implements Rule
{
    public $message;
    /**
     * Create a new rule instance.
     *
     */
    public function __construct()
    {
        $this->message = '';
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        $keys = array_keys($value);

        if (!is_array($value)) {
            $this->message = '地位坐标必须是数组格式';
            return false;
        } else if (!in_array('lng', $keys) || !in_array('lat', $keys)) {
            $this->message = '地位坐标key必须包含 经度：lng, 纬度：lat';
            return false;
        }

        return true;
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return $this->message;
    }
}
